package com.ccys.app.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ccys.app.service.DoctorListService;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.cache.UserUtil;
import com.ccys.db.entity.TblMember;
import com.ccys.db.mapper.*;
import com.ccys.db.vo.app.doctorList.GetDoctorDetailMakeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: WhiteCoat
 * @description: Member获取医生的接口实现
 * @author: ZhangJingCan
 * @create: 2024-01-19 14:09
 **/

@Service
public class DoctorListServiceImpl implements DoctorListService {

    @Resource
    private TblDoctorMapper tblDoctorMapper;

    /**
     * 医生的获奖
     */
    @Resource
    private TblDoctorAwardsMapper tblDoctorAwardsMapper;

    /**
     * 医生的教育经历
     */
    @Resource
    private TblDoctorEducationMapper tblDoctorEducationMapper;

    /**
     * 医生的证书
     */
    @Resource
    private TblDoctorCertificationsMapper tblDoctorCertificationsMapper;

    /**
     * 医生 -> 语言关联表
     */
    @Resource
    private TblDoctorSpeakLanguageMapper tblDoctorSpeakLanguageMapper;

    @Override
    public ResponseResultApp<GetDoctorDetailMakeVo> getDoctorDetail(String doctor_id) {
        //对方接口未校验用户是否登录 - 这里也不校验
        //校验是否传入医生ID
        if (ObjectUtil.isEmpty(doctor_id)) {
            return ResponseResultApp.error(400, "The doctor_id field is required.");
        }
        TblMember member = UserUtil.getCurLoginMember();
        String memberId = null;
        if (ObjectUtil.isNotEmpty(member.getId())) {
            memberId = member.getId();
        }

        //查询医生数据
        GetDoctorDetailMakeVo vo = tblDoctorMapper.getDoctorDetail(doctor_id, memberId);
        //判断不为空
        if (ObjectUtil.isNotEmpty(vo.getId())) {
            //医生的获奖数据 list集合的字符串
            vo.setAwards(tblDoctorAwardsMapper.findListStrByDoctorId(vo.getId()));
            //医生的教育经历
            vo.setEducations(tblDoctorEducationMapper.findNameListByDoctorId(vo.getId()));
            //医生的证书
            vo.setCertifications(tblDoctorCertificationsMapper.findNameListByDoctorId(vo.getId()));
            //医生的语言
            vo.setLanguages(tblDoctorSpeakLanguageMapper.findLanguageNameListByDoctorId(vo.getId()));
        }

        return ResponseResultApp.success(vo);
    }
}
